package util

import (
	"unicode/utf8"

	"mall/common/globalkey"
)

const (
	NAME  = 1
	MODEL = 2
)

func GetThirdPartyPlatformId(platform string) (PlatformId uint32) { // #24.09.20#
	switch platform {
	case globalkey.UserAuthTypeWechatMini, globalkey.UserAuthTypeWechat, globalkey.UserAuthTypeWechatWork:
		PlatformId = globalkey.ThirdPartyPlatformWechatMini
	}

	return
}

func UserMsgEncipher(str string, types int) string {
	switch types {
	case NAME:
		runes := []rune(str)
		maskedName := make([]rune, len(runes))
		for i, r := range runes {
			if i == 0 {
				maskedName[i] = r
			} else {
				if utf8.RuneStart(byte(r)) {
					maskedName[i] = '*'
				} else {
					maskedName[i] = r
				}
			}
		}

		return string(maskedName)
	case MODEL:
		if len(str) < 11 {
			return str
		}

		return str[:3] + "****" + str[7:]
	}

	return str
}
